
    let dengA = document.querySelector("#denglu");
    let dengB = document.querySelector("#deng");
    let sub = document.querySelector(".submitb");
    let name = document.querySelector("#usernameb");
    let pass = document.querySelector("#passwordb");
    let expires =document.querySelector("#seven-btn");
    let coverImg = document.querySelector("#coverImg");


    let one = document.querySelector(".one");//登录注册
    let two = document.querySelector(".two");//欢迎，注销  
    let ming =  document.querySelector(".ming")//用户名
    //默认页面隐藏
    dengB.classList.add('hidden')

    sub.onclick = function(){
        let username = name.value;
        let password = pass.value;
        
        $.post('/api/user/login',{username,password,expires:expires.checked ? 7 : 0 },reg =>{
            //数据库验证成功
            if(reg.code === 200){
               alert('登录成功！')
               dengB.classList.remove('hidden')
               dengA.classList.add('hidden')
               one.classList.add('hidden')
               two.classList.remove('hidden')
            }else if(reg.code === 300){
                alert('密码输入错误！')
            }else{
                alert("还未注册，请先注册！")
            }
            setTimeout(() => {
                $('#shoplog').modal('hide')
                name.value = ""
                pass.value = ""
            },20)
        })
    }
  
    //登陆后根据后台传入的token判断是否存在，显示username
    $.get('/api/user/isLogin', resp =>{
        if(resp.code === 200){
            ming.innerHTML = resp.body.username;
            coverImg.setAttribute("src",resp.body.avatar)
         }
    })
    
    //注销，删除session里的数据
    two.onclick = function(e){
        if(e.target.className === 'logout'){
            if(confirm("确定要退出吗?")){
                $.get('/api/user/unLogin',resp =>{
                    two.classList.add('hidden')
                    one.classList.remove('hidden')
                    dengB.classList.add('hidden')
                    dengA.classList.remove('hidden')
                })
            }
        }
    }

    //点击注销，让名字过期
    // two.onclick = function(e){
    //     if(e.target.className === 'logout'){
    //         setCookie('username',' ',{expires:-1,path:'/'});
    //         two.classList.add('hidden')
    //         one.classList.remove('hidden')
    //         dengB.classList.add('hidden')
    //         dengA.classList.remove('hidden')
    //     }
    // }

    //如果成功，则判断姓名username 是否存在然后显示
    // let mingzi = getCookie('username');
  
    // if(mingzi){
    //     dengB.classList.remove('hidden')
    //     dengA.classList.add('hidden')
    //     one.classList.add('hidden')
    //     two.classList.remove('hidden')
    //     two.innerHTML = `<li><a href="">欢迎您，<b class="ming">${mingzi}</b></a></li>
    //     <li class="tuichu"><a class="logout" href="#">注销</a></li>`
      
    // }else{
    //     two.classList.add('hidden')
    //     one.classList.remove('hidden')
    //     dengA.classList.remove('hidden')
    //     dengB.classList.add('hidden')
    // }
   

    
              